Repository navigation
Conversation
When a JavaScript-backed ReadableStream errors while it is piped to a WritableStream, the pipe reported an unhandled rejection even though the caller handled the pipeTo() promise and every other promise it could see. This happens with JavaScript-backed writables (including crypto.DigestStream and tee() branches piped to them) and with internal ones such as IdentityTransformStream. Both pipe loops return promises that are already rejected from promise continuations. V8 attaches the handler that adopts such a promise only in a later microtask. When unhandled rejections are processed in a microtask, which is the behavior without the unhandled_rejection_after_microtask_checkpoint compatibility flag, that processing can run first and report the promise. These promises are only steps of the pipe: the caller learns the outcome from the pipe promise, which is settled on its own. Mark them as handled through a new rejectedPipeStep() helper. This replaces the pipeThrough-only marking in the JavaScript-backed pipe loop, so the IsPipeThrough parameter of rejectAfterCancel() goes away. The internal readable's read-failure continuation returns a rejected promise the same way, and is reached when the pipe aborts an internal writable whose readable side is being read; mark that one handled too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add regression cases for an IdentityTransformStream readable that is piped into a DigestStream and errors because its writable side is aborted, with and without preventAbort. Each used to report two unhandled rejections: one from the internal readable's read-failure continuation and one from the JavaScript-backed pipe loop. The previous commit fixes both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Closing: this change continues downstream. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a JavaScript-backed
ReadableStreamerrors while piped to aWritableStream, workerd reports an unhandled rejection even though the caller handles thepipeTo()promise and every other promise it can see:It reproduces with JavaScript-backed writables (
DigestStream,new WritableStream(),tee()branches piped to them) and with internal ones (IdentityTransformStream). It also reproduces with an internal source, such as anIdentityTransformStreamreadable piped into aDigestStreamwhose writable side is aborted, with or withoutpreventAbort. The noise makesworkerd testruns fail and clutters logs.Cause
Both pipe loops (
WritableStreamJsController::pipeLoopinstandard.c++,WritableStreamInternalController::Pipe::pipeLoopininternal.c++) return promises from promise continuations that are already rejected. V8 attaches the handler that adopts such a promise only in a later microtask (the promise-resolve-thenable job). Withoutunhandled_rejection_after_microtask_checkpoint, unhandled rejections are processed in a microtask, which runs before that job and reports the promise. The internal readable's read-failure continuation does the same, and the pipe reaches it when aborting an internal writable whose readable side is being read.Fix
These promises are only steps of the pipe: the caller learns the outcome from the pipe promise, which is settled on its own (and is still reported if the caller doesn't handle it). Add a
rejectedPipeStep()helper that returns them marked as handled, and use it at every such site. This replaces the JavaScript-backed loop's marking that applied only topipeThrough(), soIsPipeThroughand the corresponding parameter ofrejectAfterCancel()are removed. The read-failure continuation marks its promise handled too.Testing
pipe-js-source-error-unhandled-rejection-testcovers a byte source and a default source piped toDigestStream, a byte source piped toIdentityTransformStream, a teed source with both branches piped toDigestStreams, and an abortedIdentityTransformStreamreadable piped into aDigestStream, with and withoutpreventAbort. It pinsno_unhandled_rejection_after_microtask_checkpoint, the behavior under which these were reported. All six cases fail without the fix and pass with it, 5/5 runs.@all-autogatesand@all-compat-flagsvariants.🤖 Generated with Claude Code